<template>
    <div style="width: 50%">
        <pt-form :rules="formRule" url="configures" ref="formRef"></pt-form>
    </div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import { system } from '@/api'

const formRef = ref()
const formRule = {
    rules: [
        {
            label: '站点状态',
            field: 'status',
            type: 'radio',
            options: [
                { label: '开启', value: '1' },
                { label: '关闭', value: '0' },
            ],
            value: '1',
        },
        { label: '站点标题', field: 'title', value: '' },
        { label: '站点LOGO', field: 'logo', type: 'image' },
        { label: '网站地址', field: 'url', value: '' },
        { label: 'SEO标题', field: 'seo_title' },
        { label: 'SEO关键字', field: 'seo_keyword' },
        { label: 'SEO描述', field: 'seo_description', type: 'textarea' },
        { label: '版权信息', field: 'copyright' },
        { label: '备案号', field: 'filing_number' },
        { label: '公安备案号', field: 'police_filing_number' },
    ],
}

const loadData = () => {
    system.getConfig().then((res) => {
        const data: Record<string, any> = {}
        res.data?.forEach((item: any) => {
            data[item.name] = item.value
        })
        formRef.value.action.reload(data)
    })
}

const init = () => {
    formRef.value.action.on('submitted', () => {})
}

onMounted(() => {
    init()
    loadData()
})
</script>
